import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import {formatMessage} from './intl';
import stringify from 'Shared/utils/stringify';
import {InitData, List, Detail} from './DTO';
const baseUrl = '/afterSales/api/v1';
const resourceName = formatMessage({
    id: 'api.resourceName',
    defaultMessage: '技术升级结算'
});

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询{resourceName}'
}, {resourceName});

const addDesc = formatMessage({
    id: 'api.message.addDesc',
    defaultMessage: '新增{resourceName}'
}, {resourceName});


const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询{resourceName}详情'
}, {resourceName});


const updateDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '编辑{resourceName}'
}, {resourceName});

const submitDesc = formatMessage({
    id: 'api.message.submitDesc',
    defaultMessage: '提交{resourceName}'
}, {resourceName});

const abandonDesc = formatMessage({
    id: 'api.message.abandonDesc',
    defaultMessage: '作废{resourceName}'
}, {resourceName});

const resettleDesc = formatMessage({
    id: 'api.message.resettleDesc',
    defaultMessage: '反结算'
});

const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出{resourceName}'
}, {resourceName});

const passDesc = formatMessage({
    id: 'api.message.passDesc',
    defaultMessage: '审核通过'
});

const rejectDesc = formatMessage({
    id: 'api.message.rejectDesc',
    defaultMessage: '审核不通过'
});

const sourceOrderDesc = formatMessage({
    id: 'api.message.sourceOrderDesc',
    defaultMessage: '查询待结算单据'
});

// 初始化查询
export const initQuery = () => request(`${baseUrl}/ui/technologyActivityClaimSettlement/init`, null, InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, initQuery));

// 查询
export const getList = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/technologyActivityClaimSettlements/forCurrentUser?${queryString}`, null, List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 新增
export const addInfo = data => request(`${baseUrl}/technologyActivityClaimSettlements`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, addDesc));

// 查询详情
export const getDetail = id => request(`${baseUrl}/technologyActivityClaimSettlements/${id}`, null, Detail)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getDetailDesc));

// 编辑
export const updateInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDesc));

// 提交
export const submitInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}/submit`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, submitDesc));

// 作废
export const abandonInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}/abandon`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, abandonDesc));

// 反结算
export const reSettleInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}/reSettlement`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, resettleDesc));

// 审核通过
export const passInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}/pass`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, passDesc));

// 审核不通过
export const rejectInfo = (id, data) => request(`${baseUrl}/technologyActivityClaimSettlements/${id}/reject`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, rejectDesc));

// 导出
export const exportInfo = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/technologyActivityClaimSettlements/export/forCurrentUser?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};

// 查询待结算的技术升级单据
export const getTechnologyActivitys = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/technologyActivities/forClaimSettlements?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, sourceOrderDesc));
};
// 快捷查询待结算的技术升级单据
export const getTechnologyActivitySimple = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/technologyActivities/forClaimSettlements/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, sourceOrderDesc));
};
// 查询待结算的技术升级索赔单
export const getActivityClaims = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/technologyActivityClaims/forClaimSettlements?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, sourceOrderDesc));
};
const getDealerDesc = formatMessage({
    id: 'api.message.getDealerDesc',
    defaultMessage: '查询总代信息'
});
// 查询服务站
export const getDealers = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dealers/forServiceInformation?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealerDesc));
};
//根据条件查询总代子公司
export const getDealerSimple = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dealers/forServiceInformation/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealerDesc));
};
